﻿package j.sus2maj7.encoding
{
	import flash.utils.ByteArray;
	
	import j.sus2maj7.util.*;
	import j.sus2maj7.ability.*;
	
	public class AbstractBinary extends AbstractDestroyable implements IBinary
	{
		private var _ba:ByteArray;
		
		public function AbstractBinary(ba:ByteArray=null)
		{
			if (ba == null) _ba = new ByteArray();
			else _ba = ba;
		}
		public function toString():String
		{
			return "Length: " + _ba.length + "\n" + ByteUtil.print( this._ba );
		}
		
		public function get ba():ByteArray { return _ba; }
		
		//wraps byteArray
		public function get bytesAvailable():uint
		{
			return _ba.bytesAvailable;
		}
		public function get endian():String
		{
			return _ba.endian;
		}
		public function set endian(value:String):void
		{
			_ba.endian = value;
		}
		public function get length():uint
		{
			return _ba.length;
		}
		public function set length(value:uint):void
		{
			_ba.length = value;
		}
		public function get objectEncoding():uint
		{
			return _ba.objectEncoding;
		}
		public function set objectEncoding(value:uint):void
		{
			_ba.objectEncoding = value;
		}
		public function get position():uint
		{
			return _ba.position;
		}
		public function set position(value:uint):void
		{
			_ba.position = value;
		}
		
		//compress/uncompress
		public function compress():void
		{
			_ba.compress();
		}
		public function uncompress():void
		{
			_ba.uncompress();
		}
		
		//read
		public function readBoolean():Boolean
		{
			return _ba.readBoolean();
		}
		public function readByte():int
		{
			return _ba.readByte();
		}
		public function readBytes(bytes:ByteArray, offset:uint=0, length:uint=0):void
		{
			return _ba.readBytes(bytes, offset, length);
		}
		public function readDouble():Number
		{
			return _ba.readDouble();
		}
		public function readFloat():Number
		{
			return _ba.readFloat();
		}
		public function readInt():int
		{
			return _ba.readInt();
		}
		public function readMultiByte(length:uint, charSet:String):String
		{
			return _ba.readMultiByte(length, charSet);
		}
		public function readObject():*
		{
			return _ba.readObject();
		}
		public function readShort():int
		{
			return _ba.readShort();
		}
		public function readUnsignedByte():uint
		{
			return _ba.readUnsignedByte();
		}
		public function readUnsignedInt():uint
		{
			return _ba.readUnsignedInt();
		}
		public function readUnsignedShort():uint
		{
			return _ba.readUnsignedShort();
		}
		public function readUTF():String
		{
			return _ba.readUTF();
		}
		public function readUTFBytes(length:uint):String
		{
			return _ba.readUTFBytes(length);
		}
		
		//write
		public function writeBoolean(value:Boolean):void
		{
			_ba.writeBoolean(value);
		}
		public function writeByte(value:int):void
		{
			_ba.writeByte(value);
		}
		public function writeBytes(bytes:ByteArray, offset:uint=0, length:uint=0):void
		{
			_ba.writeBytes(bytes, offset, length);
		}
		public function writeDouble(value:Number):void
		{
			_ba.writeDouble(value);
		}
		public function writeFloat(value:Number):void
		{
			_ba.writeFloat(value);
		}
		public function writeInt(value:int):void
		{
			_ba.writeInt(value);
		}
		public function writeMultiByte(value:String, charSet:String):void
		{
			_ba.writeMultiByte(value, charSet);
		}
		public function writeObject(value:*):void
		{
			_ba.writeObject(value);
		}
		public function writeShort(value:int):void
		{
			_ba.writeShort(value);
		}
		public function writeUnsignedInt(value:uint):void
		{
			_ba.writeUnsignedInt(value);
		}
		public function writeUTF(value:String):void
		{
			_ba.writeUTF(value);
		}
		public function writeUTFBytes(value:String):void
		{
			_ba.writeUTFBytes(value);
		}
	}
}